{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "is_executing": true
    }
   },
   "source": [
    "import plotly\n",
    "from flask import Flask, jsonify,request\n",
    "from kaleido.scopes import plotly\n",
    "import pandas as pd\n",
    "import vanna.flask as vanna_flask\n",
    "import plotly.express as px\n",
    "from vanna.remote import VannaDefault\n",
    "from vanna.flask import VannaFlaskApp\n",
    "\n",
    "app = Flask(__name__)\n",
    "\n",
    "m_vn = VannaDefault(model='chinook', api_key='253e0c6afda74a15bcaa5e81e24e67ee')\n",
    "m_vn.connect_to_sqlite('https://vanna.ai/Chinook.sqlite')\n",
    "\n",
    "vanna_app = VannaFlaskApp(m_vn)\n",
    "\n",
    "@app.route('/generate_plotly_figure',methods=['POST'])\n",
    "def generate_plotly_figure_route():\n",
    "    question = request.json.get('question')\n",
    "    result = m_vn.ask(question)\n",
    "    df = pd.DataFrame(result)\n",
    "\n",
    "    return jsonify(vanna_app.generate_plotly_figure(df))\n",
    "\n",
    "vanna_app.run()\n",
    "\n",
    "@app.route(\"/api/v0/train\", methods=[\"POST\"])\n",
    "def add_training_data():\n",
    "  question = request.json.get('question')\n",
    "  sql = m_vn.request.json.get(\"sql\")\n",
    "  ddl = m_vn.request.json.get(\"ddl\")\n",
    "  documentation = m_vn.request.json.get(\"documentation\")\n",
    "  question_function=m_vn.request.json.get(\"question_function\")(\"question_function\")\n",
    "\n",
    "  return jsonify(vanna_app.add_training_data())\n",
    "\n"
   ],
   "execution_count": null,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "execution_count": null,
   "source": "",
   "id": "650298955547fe52",
   "outputs": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
